package org.wmq.travelagency02.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.wmq.travelagency02.mapper.GroupMessageMapper;
import org.wmq.travelagency02.model.DTO.HistoryGroupMessageQueryDTO;
import org.wmq.travelagency02.model.Entity.GroupMessage;
import org.wmq.travelagency02.service.GroupMessageService;

@Service
@RequiredArgsConstructor
public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, GroupMessage> implements GroupMessageService {
    private final GroupMessageMapper groupMessageMapper;

    @Override
    public Page<GroupMessage> getHistoryMessages(HistoryGroupMessageQueryDTO historyGroupMessageQueryDTO) {
        return this.lambdaQuery().eq(GroupMessage::getChatGroupId, historyGroupMessageQueryDTO.getChatGroupId())
                .select(GroupMessage::getSenderId, GroupMessage::getContent)
                .orderByDesc(GroupMessage::getCreateTime)
                .page(Page.of(historyGroupMessageQueryDTO.getPageNo(), 10));
    }

    @Override
    public Page<GroupMessage> getMessages(Long chatGroupId) {
        return this.getHistoryMessages(new HistoryGroupMessageQueryDTO(chatGroupId, 1L));
    }
}
